package async

import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlin.system.measureTimeMillis


private suspend fun getTime1(): Int {
    delay(1000)
    return 1
}

private suspend fun getTime2(): Int {
    delay(1000)
    return 2
}


fun main(args: Array<String>) {
    runBlocking {
        val time = measureTimeMillis {
            val one = async(start = CoroutineStart.LAZY) {
                getTime1()
            }
            val two = async(start = CoroutineStart.LAZY) {
                getTime2()
            }
            one.await() + two.await()
        }
        println("Completed in $time ms")
    }
}
